﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DrivingCRM.Model;

namespace DrivingCRM.Views.Private.CRM
{
    public partial class AddBill : System.Web.UI.Page
    {
        public List<Package> packages = new List<Package>();
        public List<Product> products = new List<Product>();
        public List<int> packagesQuantity = new List<int>();
        public List<int> productsQuantity = new List<int>();
        public List<int> packagesPrice = new List<int>();
        public List<int> productsPrice = new List<int>();

        protected void Page_Load(object sender, EventArgs e)
        {
            //this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
        }

        //protected void Page_LoadComplete(object sender, EventArgs e)
        //{
        //    if (this.DDL_Packages.Items.Count == 0)
        //        this.B_AddPackage.Enabled = false;

        //    if (this.DDL_Products.Items.Count == 0)
        //        this.B_AddProduct.Enabled = false;
        //}

        /// <summary>
        /// Méthode déclenché au clic sur le bouton d'ajout d'un package à la facture
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void B_AddPackage_Click(object sender, EventArgs e)
        {
            try
            {
                int qtt = 0;
                ListItem lstItem = this.DDL_Packages.SelectedItem;
                if (string.IsNullOrEmpty(this.TB_QuantityPackage.Text) == false && (int.TryParse(this.TB_QuantityPackage.Text, out qtt)) && qtt > 0)
                {
                    this.packagesQuantity.Add(qtt);
                    this.L_ErrorMessage.Text = "Prestation ajoutée";


                    this.UP_Bill.Update();
                }
                else
                    this.L_ErrorMessage.Text = "Veuillez saisir une quantité correcte (ex: 1 ou 14)";
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// Méthode déclenché au clic sur le bouton d'ajout d'un produit à la facture
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void B_AddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                int qtt = 0;
                ListItem lstItem = this.DDL_Products.SelectedItem;
                if (string.IsNullOrEmpty(this.TB_QuantityProduct.Text) == false && (int.TryParse(this.TB_QuantityProduct.Text, out qtt)) && qtt > 0)
                {
                    this.productsQuantity.Add(qtt);
                    this.L_ErrorMessage.Text = "Prestation ajoutée";

                    this.UP_Bill.Update();
                }
                else
                    this.L_ErrorMessage.Text = "Veuillez saisir une quantité correcte (ex: 1 ou 14)";
            }
            catch (Exception ex)
            {

            }
        }
    }
}